package collecion.nexd.com.newnexdcollection.modle;


/**
 * Created by xu on 2015/8/18.
 * all sensor datas save object
 * 将所有采集到的传感器数据，存储在对象中，每次将重写toString()方法后拼接出来的结果返回给需要的地方
 */
public class SensorDataObject {
    StringBuffer stringBuffer = new StringBuffer();
    private long index = 0;
    private float[] projectionMatrix = new float[]{-1, -1, -1, -1, -1, -1, -1, -1, -1}; // 长度为9
    private float[] accelerometer = new float[]{-1, -1, -1}; // 加速度传感器    3
    private float[] linear_accelerometer = new float[]{-1, -1, -1}; // 线性加速度传感器  3
    private float[] gravity = new float[]{-1, -1, -1}; // 重力传感器         3
    private float[] gyroscope = new float[]{-1, -1, -1}; // 陀螺仪传感器     3
    private float[] orientation = new float[]{-1, -1, -1}; // 长度 3
    private float[] magnetic_field = new float[]{-1, -1, -1}; // 磁场传感器  3
    private float[] rotation_vector = new float[]{-1, -1, -1, -1, -1}; // 旋转矢量   5
    private float[] getOrientation = new float[]{-1, -1, -1}; // 长度 3
    private float[] pressure = new float[]{-1};// 压力传感器 1
    private float[] temperature = new float[]{-1}; //  温度， 长度 1
    private float[] light = new float[]{-1}; // 光线传感器  1
    private float[] proximity = new float[]{-1}; // 接近传感器  1
    private float[] relative_humidity = new float[]{-1}; // 相对湿度传感器 1     // 这之前的数据都是对的
    private float stepdetect = -1.0f; // 计步器   1
    // 以上是前 44
    // 这里是中间插入的时间戳
    private long timestamp = -1;   //1
    // 一下是44-69
    private double[] gyro_integration = new double[]{-1, -1, -1}; //    44-46        3
    private float[] game_rotation_vector = new float[]{-1, -1, -1, -1}; //   50-52       4            // 长度 4
    private float[] geomagnetic_rotation_vector = new float[]{-1, -1, -1, -1, -1}; //53-55   5              // 长度 5
    private float[] step_counter = new float[]{-1}; // 1  56
    private float[] magnetic_field_uncalibrated = new float[]{-1, -1, -1, -1, -1, -1}; // 6   57-62
    private float[] gyroscope_uncalibrated = new float[]{-1, -1, -1, -1, -1, -1}; // 6   63-68


    @Override
    public String toString() {
        // 先对stringbuffer进行清空，防止每次都重新创建Stringbuffer对象，导致内存泄漏。
        stringBuffer.setLength(0);

        stringBuffer.append(index).append(" ");

        for (int i = 0; i < projectionMatrix.length; i++) {
            stringBuffer.append(projectionMatrix[i]).append(" ");
        }

        for (int i = 0; i < accelerometer.length; i++) {
            stringBuffer.append(accelerometer[i]).append(" ");
        }

        for (int i = 0; i < linear_accelerometer.length; i++) {
            stringBuffer.append(linear_accelerometer[i]).append(" ");
        }

        for (int i = 0; i < gravity.length; i++) {
            stringBuffer.append(gravity[i]).append(" ");
        }

        for (int i = 0; i < gyroscope.length; i++) {
            stringBuffer.append(gyroscope[i]).append(" ");
        }

        for (int i = 0; i < orientation.length; i++) {
            stringBuffer.append(orientation[i]).append(" ");
        }

        for (int i = 0; i < magnetic_field.length; i++) {
            stringBuffer.append(magnetic_field[i]).append(" ");
        }

        for (int i = 0; i < rotation_vector.length; i++) {
            stringBuffer.append(rotation_vector[i]).append(" ");
        }

        for (int i = 0; i < getOrientation.length; i++) {
            stringBuffer.append(getOrientation[i]).append(" ");
        }

        stringBuffer.append(pressure[0]).append(" ");

        stringBuffer.append(temperature[0]).append(" ");

        stringBuffer.append(light[0]).append(" ");

        stringBuffer.append(proximity[0]).append(" ");

        stringBuffer.append(relative_humidity[0]).append(" ");

        stringBuffer.append(stepdetect).append(" ");

        stringBuffer.append(timestamp).append(" ");

        for (int i = 0; i < gyro_integration.length; i++) {
            stringBuffer.append(gyro_integration[i]).append(" ");
        }

        for (int i = 0; i < game_rotation_vector.length; i++) {
            stringBuffer.append(game_rotation_vector[i]).append(" ");
        }

        for (int i = 0; i < geomagnetic_rotation_vector.length; i++) {
            stringBuffer.append(geomagnetic_rotation_vector[i]).append(" ");
        }

        for (int i = 0; i < step_counter.length; i++) {
            stringBuffer.append(step_counter[i]).append(" ");
        }

        for (int i = 0; i < magnetic_field_uncalibrated.length; i++) {
            stringBuffer.append(magnetic_field_uncalibrated[i]).append(" ");
        }

        for (int i = 0; i < gyroscope_uncalibrated.length; i++) {
            stringBuffer.append(gyroscope_uncalibrated[i]).append(" ");
        }

        stringBuffer.append("\n");
        return stringBuffer.toString();
    }

    public void setIndex(long index) {
        this.index = index;
    }

    public void setProjectionMatrix(float[] projectionMatrix) {
        this.projectionMatrix = projectionMatrix;
    }

    public void setAccelerometer(float[] accelerometer) {
        this.accelerometer = accelerometer;
    }

    public void setLinear_accelerometer(float[] linear_accelerometer) {
        this.linear_accelerometer = linear_accelerometer;
    }

    public void setGravity(float[] gravity) {
        this.gravity = gravity;
    }

    public void setGyroscope(float[] gyroscope) {
        this.gyroscope = gyroscope;
    }

    public void setGetOrientation(float[] getOrientation) {
        this.getOrientation = getOrientation;
    }

    public void setMagnetic_field(float[] magnetic_field) {
        this.magnetic_field = magnetic_field;
    }

    public void setRotation_vector(float[] rotation_vector) {
        if (rotation_vector.length != this.rotation_vector.length) {
            System.arraycopy(rotation_vector, 0, this.rotation_vector, 0, rotation_vector.length);
        } else {
            this.rotation_vector = rotation_vector;
        }
    }

    public void setOrientation(float[] orientation) {
        this.orientation = orientation;
    }

    public void setPressure(float[] pressure) {
        this.pressure = pressure;
    }

    public void setTemperature(float[] temperature) {
        this.temperature = temperature;
    }

    public void setLight(float[] light) {
        this.light = light;
    }

    public void setProximity(float[] proximity) {
        this.proximity = proximity;
    }

    public void setRelative_humidity(float[] relative_humidity) {
        this.relative_humidity = relative_humidity;
    }

    public void setStepdetect(float stepdetect) {
        this.stepdetect = stepdetect;
    }

    public void setTimestamp(long timestamp) {
        this.timestamp = timestamp;
    }

    public void setGyro_integration(double[] gyro_integration) {
        this.gyro_integration = gyro_integration;
    }

    public void setGame_rotation_vector(float[] game_rotation_vector) {
        if (game_rotation_vector.length != this.game_rotation_vector.length) {
            System.arraycopy(game_rotation_vector, 0, this.game_rotation_vector, 0, game_rotation_vector.length);
        } else {
            this.game_rotation_vector = game_rotation_vector;
        }
    }

    public void setGeomagnetic_rotation_vector(float[] geomagnetic_rotation_vector) {
        if (geomagnetic_rotation_vector.length != this.geomagnetic_rotation_vector.length) {
            System.arraycopy(geomagnetic_rotation_vector, 0, this.geomagnetic_rotation_vector, 0, geomagnetic_rotation_vector.length);
        } else {
            this.geomagnetic_rotation_vector = geomagnetic_rotation_vector;
        }
    }

    public void setStep_counter(float[] step_counter) {
        this.step_counter = step_counter;
    }

    public void setMagnetic_field_uncalibrated(float[] magnetic_field_uncalibrated) {
        this.magnetic_field_uncalibrated = magnetic_field_uncalibrated;
    }

    public void setGyroscope_uncalibrated(float[] gyroscope_uncalibrated) {
        this.gyroscope_uncalibrated = gyroscope_uncalibrated;
    }
}
